package com.chuangshixinchen.enterprise.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chuangshixinchen.enterprise.common.JwtUtils;
import com.chuangshixinchen.enterprise.common.Result;
import com.chuangshixinchen.enterprise.common.StatusCode;
import com.chuangshixinchen.enterprise.entity.Tb_enterprise;
import com.chuangshixinchen.enterprise.service.ITb_enterpriseService;
import com.chuangshixinchen.enterprise.vo.req.EnterpriseReqPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "企业模块", tags = "获取企业模块信息")
@RequestMapping("/enterprise")
public class EnterpriseController {

    @Autowired
    private ITb_enterpriseService enterpriseService;

    @ApiOperation(value = "查询", notes = "根据token查询详情")
    @GetMapping(value = "/info/{id}")
    @ResponseBody
    public Result<Tb_enterprise> info(@RequestHeader("Authorization") String token, @PathVariable(value = "id") Long id) {
        if (!JwtUtils.checkToken(token)){
            return new Result<Tb_enterprise>(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
        }
        Result<Tb_enterprise> result = enterpriseService.getInfo(id);
        return result;
    }

    @ApiOperation(value = "查询", notes = "分页查询")
    @PostMapping(value = "/page")
    @ResponseBody
    public Result<Page<Tb_enterprise>> page(@RequestHeader("Authorization") String token, @RequestBody EnterpriseReqPageVo vo) {
        if (!JwtUtils.checkToken(token)){
            return new Result<Page<Tb_enterprise>>(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
        }
        Result<Page<Tb_enterprise>> result = enterpriseService.listPage(vo);
        return result;
    }

//    @ApiOperation(value = "新增", notes = "新增")
//    @PostMapping(value = "/save")
//    @ResponseBody
//    public Result save(@RequestHeader("Authorization") String token, @RequestBody Tb_enterprise enterprise) {
//        if (!JwtUtils.checkToken(token)){
//            return new Result(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
//        }
//        Result result = enterpriseService.saveInfo(enterprise);
//        return result;
//    }

//    @ApiOperation(value = "修改", notes = "修改")
//    @PutMapping(value = "/update")
//    @ResponseBody
//    public Result update(@RequestHeader("Authorization") String token, @RequestBody Tb_enterprise enterprise) {
//        if (!JwtUtils.checkToken(token)){
//            return new Result(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
//        }
//        Result result = enterpriseService.updateInfo(enterprise);
//        return result;
//    }
}
